package com.hj.calendar.controller;


import com.hj.calendar.domain.dto.*;
import com.hj.calendar.domain.vo.CaldavAccountVO;
import com.hj.calendar.domain.vo.FsDdCalendarVO;
import com.hj.calendar.service.CaldavService;
import com.hj.response.resp.RestfulResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author hj
 * @Date 2023/5/22
 * @Description:
 */
@Tag(name = "calendar控制器")
@Slf4j
@RestController
@RequestMapping("/caldav")
public class CaldavController {

    @Resource
    private CaldavService caldavService;


    @PostMapping("/account/list")
    @Operation(summary = "01-获取钉钉/飞书的账号信息")
    public RestfulResult<List<CaldavAccountVO>> listAccount() {
        return caldavService.listAccount();
    }

    @PostMapping("/account/detail")
    @Operation(summary = "02-查看账号详情信息")
    public RestfulResult<CaldavAccountVO> accountDetail(@RequestBody DdFsDTO dto) {
        return caldavService.accountDetail(dto);
    }

    @PostMapping("/account/state")
    @Operation(summary= "03-停用或启用")
    public RestfulResult<Boolean> accountState(@RequestBody DdFsStateDTO dto) {
        return caldavService.accountState(dto);
    }

    @PostMapping("/account/delete")
    @Operation(summary = "04-删除飞书,钉钉等日历")
    public RestfulResult<Boolean> accountDelete(@RequestBody DdFsDeletedDTO dto) {
        return caldavService.accountDelete(dto);
    }

    @PostMapping("/account/setup")
    @Operation(summary = "05-上传或修改飞书,钉钉等日历的账号密码")
    public RestfulResult<CaldavAccountVO> setupAccount(@RequestBody DdFsSetupDTO dto) {
        return caldavService.setupAccount(dto);
    }


    @PostMapping("/fs/calendar")
    @Operation(summary = "06-获取飞书日历")
    public RestfulResult<List<FsDdCalendarVO>> fsCalendar(@RequestBody CaldavSelectDTO dto) {
        Date selectDay = dto.getSelectDay();
        if (null == selectDay) {
            return RestfulResult.fail("caldav获取飞书日历失败,请传入查询日期");
        }
        return caldavService.fsCalendar(selectDay);
    }

    @PostMapping("/dd/calendar")
    @Operation(summary= "07-获取钉钉日历")
    public RestfulResult<List<FsDdCalendarVO>> ddCalendar(@RequestBody CaldavSelectDTO dto) {
        Date selectDay = dto.getSelectDay();
        if (null == selectDay) {
            return RestfulResult.fail("caldav获取钉钉日历失败,请传入查询日期");
        }
        return caldavService.ddCalendar(selectDay);
    }


}
